<?php

include_once ('bn_path.php');

class bn_page
{
    private $dl;
    protected static $instance;

    function __construct()
    {
        $this->dl = new bn_dal();
    }

    public static function getInstance()
    {
        if (!isset(self::$instance))
        {
            self::$instance = new self();
        }
        return self::$instance;
    }

    public function insert($title, $text, $status, $gadget)
    {
        $this->dl->insert('pages', func_get_args());
    }

    public function delete($id)
    {
        $this->dl->delete('pages', $id);
    }

    public function update($title, $text, $status, $gadget, $id)
    {
        if ($status == '')
            $this->dl->update('pages', array(
                'title' => $title,
                'text' => $text,
                'gadget' => $gadget), array('id=' => $id));
        else
            $this->dl->update('pages', array(
                'title' => $title,
                'text' => $text,
                'status' => $status,
                'gadget' => $gadget), array('id=' => $id));
    }

    public function update_status($status, $id)
    {
        $this->dl->update('pages', array('status' => $status), array('id=' => $id));
    }

    public function select_all()
    {
        return $this->dl->select('select id,title,text,status,gadget,(select name from gadgets where id=gadget)gadname,concat("' .bn_Get_sitename() . root . '/page.php?pid=",cast(id as char))url from pages' . $sort); //(row_number()over(order by id))row,
    }

    public function select_page($id)
    {
        return $this->dl->getrow('select title,text,gadget,status from pages where id=? and status="enable"',$id);
    }
    
    public function get_page($id)
    {
        return $this->dl->getrow('select * from pages where id=?',$id);
    }

    public function get_page_id($get = 'pid')
    {
        if (isset($_GET[$get]))
            return $this->dl->getvalue('select id from pages where id=? and status="enable"',$this->gf->Get_number($_GET[$get]));
    }

    function _destruct()
    {
        unset($this->dl);
    }
}

?>